import {
  IPermissionConfig,
  PermissionType
} from "@/model/frame/IPermissionConfig";

// 读取目录中的默认权限配置信息
const configContext = require.context(
  ".",
  true,
  /^(?!.*?index|.*?IPermissionConfig).*\.ts$/ // 排除里面匹配的内容
);
const keys = configContext.keys();

const configs = {
  dir: new Array<string>(),
  route: new Array<string>()
};

keys.forEach(key => {
  configContext(key).default.forEach((item: IPermissionConfig) => {
    switch (item.type) {
      case PermissionType.ROUTE:
        configs.route.push(item.name);
        break;
      case PermissionType.DIR:
        configs.dir.push(item.name);
        break;
      case PermissionType.RESOURCE:
        break;
    }
  });
});

export default configs;
